#pragma once
#include <Windows.h>
#include <process.h>
#include<queue>
#include "GraphFitting.h"
#include "graphcut\GCoptimization.h"
const int MAX_THREAS=100;
using std::queue;

class MyThreadPool
{
public:
	MyThreadPool(int threadNumber=10);
	virtual ~MyThreadPool(void);

	void startThreads(GCoptimizationGeneralGraph* _gc,CGraphFitting* _gf);

	int addTask(int tid){ Q.push(tid); return Q.size(); }
	int fetchTask();
	void waitForThreads();
	bool finishAllTask(){return Q.empty();}
private:
	int numThreads;
	HANDLE handleArray[MAX_THREAS];  
	queue<int> Q;

	CRITICAL_SECTION cs;
//private:
//	GCoptimization* gc;
//	CGraphFitting* gf;
};

